import time
from Case.python_ui.Test_data.login_data import Logindata
from Case.python_ui.Common.basepage import Basepage
from Case.python_ui.PageLocate.product_management_locator import ProductManagementLocator
from Case.python_ui.Pageobject.admin_product_managent_pages import ProductManagementPages
from Case.python_ui.Common.commontool import CommonTool
from Case.python_ui.Test_data.common_data import Commondata
from Case.python_ui.Test_data.prod_data import Product
from selenium.webdriver.common.action_chains import ActionChains
from selenium.common.exceptions import StaleElementReferenceException
from Case.python_ui.mylogging.mylogging import MyLogging
from Case.python_ui.Common.business_common_tool import BusinessCommonTools
from Case.python_ui.PageLocate.user_slb_locator import UserSLBLocator
from Case.python_ui.PageLocate.user_my_resource_locator import UserMyResourceLocator
from selenium.common.exceptions import NoSuchElementException, ElementClickInterceptedException, \
    ElementNotInteractableException

class UserSLBPages(Basepage):

    """

    """

    # 等待页面加载转动
    def wait_web_page_rotate(self, time=100):
        doc = '等待页面加载转动图标'
        try:
            self.wait_elevisble(ProductManagementLocator.wait, doc, time)
            self.wait_eleinvisble(ProductManagementLocator.wait, doc, time)
        except:
            pass


    """
    
    """
    #进入my resource界面
    def enter_my_resource_page(self):
        doc='进入user端的myresource页面'
        for i in range(3):
            try:
                self.wait_elevisble(ProductManagementLocator.my_resource_tab, doc)
                self.click_element(ProductManagementLocator.my_resource_tab, doc)
                break
            except:
                self.refresh_page()
                continue
        time.sleep(5)
        #self.wait_elevisble(ProductManagementLocator.page_total,doc)
        self.wait_elevisble(UserMyResourceLocator.reset_button, doc)
        self.click_element(UserMyResourceLocator.reset_button, doc)
        time.sleep(5)


    def get_prod_name_to_click(self,prod_name):
        doc='获取产品名称然后点击'
        prod_list=self.get_elements(ProductManagementLocator.prod_list,doc)
        time.sleep(2)
        for prod in prod_list:
            if prod.text == prod_name:
                prod.click()
        time.sleep(2)

    # 校验某个属性值是否符合预期
    def check_attribute(self, real_result, except_result):
        if real_result == except_result:
            assert True
        else:
            assert False, '实际值:' + real_result + '期望值:' + except_result

    # 判断是否包含元素
    def check_contain_str(self, string, except_string):
        if except_string in string:
            assert True
        else:
            assert False, '实际值:' + string + '期望值:' + except_string

    # 获得最新创建的instance id
    def get_instance_id(self,cmdopt,get_database_source):
        instance_id = BusinessCommonTools().get_instance_id(cmdopt, get_database_source)
        return instance_id


    # 清空筛选状态
    def clear_filter_status(self, locate, status_filter_reset_button, status_filter_ok_button):
        doc = '清空筛选状态'
        try:
            # 点击筛选按钮
            time.sleep(2)
            self.click_element(locate, doc)
            time.sleep(2)
            # 点击reset按钮
            self.click_element(status_filter_reset_button, doc)
        except ElementNotInteractableException as e:
            self.click_element(status_filter_ok_button, doc)
            return
        except ElementClickInterceptedException as e:
            self.click_element(status_filter_ok_button, doc)
            return
        else:
            time.sleep(2)
            self.click_element(status_filter_ok_button, doc)
            return



        # order界面筛选项清空
    def orders_clear_status(self):
        self.clear_filter_status(UserSLBLocator.product_filter_button, UserSLBLocator.status_filter_reset_button,
                                 UserSLBLocator.status_filter_ok_button)
        time.sleep(2)
        self.clear_filter_status(UserSLBLocator.order_type_filter_button, UserSLBLocator.status_filter_reset_button2,
                                 UserSLBLocator.status_filter_ok_button2)
        time.sleep(2)
        self.clear_filter_status(UserSLBLocator.order_status_filter_button, UserSLBLocator.status_filter_reset_button3,
                                 UserSLBLocator.status_filter_ok_button3)
        time.sleep(2)
        self.clear_filter_status(UserSLBLocator.billing_method_filter_button,
                                 UserSLBLocator.status_filter_reset_button4, UserSLBLocator.status_filter_ok_button4)

    #购买SLB(subscription-intranet)
    def create_slb_subscription_instranet(self):
        doc = '购买SLB(subscription-intranet)'
        name = 'slb_'+ CommonTool.generate_string()
        print(name)
        #success = 'Release Successfully'
        self.enter_my_resource_page()
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.get_prod_name_to_click('Server Load Balancer')
        time.sleep(2)
        self.switch_to_new_window()
        self.wait_web_page_rotate(10)
        self.wait_elevisble(UserSLBLocator.instance_name, doc)
        self.send_keys(UserSLBLocator.instance_name, name, doc)
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.intranet_button, doc)
        self.click_element(UserSLBLocator.intranet_button, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.vpc_select, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.vpc_first_select, doc)
        time.sleep(5)
        self.click_element(UserSLBLocator.vswitch_select, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.vswitch_first_select,doc)
        time.sleep(2)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.wait_elevisble(ProductManagementLocator.pay_button, doc)
        time.sleep(5)
        self.click_element(ProductManagementLocator.term_of_service, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        return  name


    #进入控制台，用name查询得到instance_id
    def get_slb_instance_id(self, intance_name):
        doc = '入控制台，用name查询得到instance_id'
        self.driver.refresh()
        self.wait_elevisble(ProductManagementLocator.menu_list, doc)
        self.click_element(ProductManagementLocator.menu_list, doc)
        self.get_console_product_to_click('Server Load Balancer')
        time.sleep(4)
        self.wait_elevisble(ProductManagementLocator.iframe, doc)
        self.driver.switch_to.frame(self.get_element(ProductManagementLocator.iframe, doc))
        for i  in range(3):
            try:
                self.wait_elevisble(UserSLBLocator.slb_instance_management,doc)
                break
            except:
                time.sleep(5)
                continue
        self.click_element(UserSLBLocator.slb_instance_management,doc)
        self.query_instance(intance_name)
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.slb_instance_id_ele, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.slb_instance_id_ele, doc)
        self.wait_elevisble(UserSLBLocator.slb_instance_id,doc)
        time.sleep(2)
        intance_id = self.get_element(UserSLBLocator.slb_instance_id,doc).text
        self.driver.switch_to.default_content()
        print(intance_id)
        return intance_id

    def modify_slb(self, cmdopt,instance_id):
        doc = '变配slb'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        time.sleep(5)
        self.query_intance_id(instance_id)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.move_mouse_to_click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Modify')
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        time.sleep(2)
        eles=self.get_elements(UserSLBLocator.slb_instance_edition,doc)
        eles[0].click()
        time.sleep(2)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        time.sleep(2)
        self.click_element(ProductManagementLocator.term_of_service, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])

    #注释相关代码
        # all_handles = self.driver.window_handles
        # self.driver.switch_to.window(all_handles[0])
        # instance_id = BusinessCommonTools().get_instance_id(cmdopt,get_database_source)
        # time.sleep(2)
        # self.wait_elevisble(UserMyResourceLocator.reset_button, doc)
        # self.click_element(UserMyResourceLocator.reset_button, doc)
        # time.sleep(5)
        # self.wait_elevisble(UserMyResourceLocator.instance_id_input, doc)
        # self.send_keys(UserMyResourceLocator.instance_id_input, instance_id, doc)
        # time.sleep(2)
        # self.wait_elevisble(UserMyResourceLocator.orgnazation_search, doc)
        # self.click_element(UserMyResourceLocator.orgnazation_search, doc)
        # time.sleep(5)
        # self.wait_elevisble(UserSLBLocator.actions_button, doc)
        # self.click_element(UserSLBLocator.actions_button, doc)
        # time.sleep(2)
        # self.click_element(UserSLBLocator.release_button, doc)
        # time.sleep(2)
        # self.switch_to_new_window()
        # time.sleep(5)
        # self.wait_elevisble(UserSLBLocator.real_release_button, doc)
        # self.click_element(UserSLBLocator.real_release_button, doc)
        # time.sleep(2)
        # self.wait_elevisble(UserSLBLocator.confirm_release_button, doc)
        # self.click_element(UserSLBLocator.confirm_release_button, doc)
        # time.sleep(5)
        # self.check_attribute(self.get_element(UserSLBLocator.release_success, doc).text, success)



    #购买SLB(psyg-intranet) + 释放
    def create_slb_pag_instranet(self, cmdopt, get_database_source):
        doc = '购买SLB(psyg-intranet)'
        name =  'lsb_'+ CommonTool.generate_string()
        success = 'Release Successfully'
        self.enter_my_resource_page()
        self.wait_elevisble(UserMyResourceLocator.reset_button, doc)
        self.click_element(UserMyResourceLocator.reset_button, doc)
        time.sleep(5)
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.get_prod_name_to_click('Server Load Balancer')
        time.sleep(2)
        self.switch_to_new_window()
        time.sleep(5)
        self.wait_elevisble(UserSLBLocator.pag_buttoon, doc)
        self.click_element(UserSLBLocator.pag_buttoon, doc)
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.instance_name, doc)
        self.send_keys(UserSLBLocator.instance_name, name, doc)
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.intranet_button, doc)
        self.click_element(UserSLBLocator.intranet_button, doc)
        time.sleep(2)
        #self.wait_elevisble(UserSLBLocator.vpc_refresh, doc)
        #self.click_element(UserSLBLocator.vpc_refresh, doc)
        #time.sleep(3)
        #self.click_element(UserSLBLocator.vpc_select, doc)
        #time.sleep(2)
        #self.click_element(UserSLBLocator.vpc_first_select, doc)
        #time.sleep(2)
        self.wait_elevisble(UserSLBLocator.vpc_select, doc)
        self.click_element(UserSLBLocator.vpc_select, doc)
        self.wait_elevisble(UserSLBLocator.vpc_option, doc)
        vpc_switch_eles = self.get_elements(UserSLBLocator.vpc_option, doc)
        vpc_switch_eles[0].click()
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.vswitch_select, doc)
        self.click_element(UserSLBLocator.vswitch_select, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.vswitch_first_select, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.buy_now_button, doc)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.click_element(ProductManagementLocator.term_of_service, doc)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.pay_button, doc)
        time.sleep(5)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        return name
        # instance_id = BusinessCommonTools().get_instance_id(cmdopt,get_database_source)
        # time.sleep(2)
        # self.wait_elevisble(UserMyResourceLocator.reset_button, doc)
        # self.click_element(UserMyResourceLocator.reset_button, doc)
        # time.sleep(5)
        # self.wait_elevisble(UserMyResourceLocator.instance_id_input, doc)
        # self.send_keys(UserMyResourceLocator.instance_id_input, instance_id, doc)
        # time.sleep(2)
        # self.wait_elevisble(UserMyResourceLocator.orgnazation_search, doc)
        # self.click_element(UserMyResourceLocator.orgnazation_search, doc)
        # time.sleep(5)
        # self.wait_elevisble(UserSLBLocator.actions_button, doc)
        # self.click_element(UserSLBLocator.actions_button, doc)
        # time.sleep(2)
        # self.click_element(UserSLBLocator.release_button, doc)
        # time.sleep(2)
        # self.switch_to_new_window()
        # time.sleep(5)
        # self.wait_elevisble(UserSLBLocator.real_release_button, doc)
        # self.click_element(UserSLBLocator.real_release_button, doc)
        # time.sleep(2)
        # self.wait_elevisble(UserSLBLocator.confirm_release_button, doc)
        # self.click_element(UserSLBLocator.confirm_release_button, doc)
        # time.sleep(5)
        # self.check_attribute(self.get_element(UserSLBLocator.release_success, doc).text, success)


    # 到期释放包年包月SLB(subscription)
    def job_release_slb_subscription(self,cmdopt, get_database_source):
        doc = '到期释放包年包月SLB(subscription)'
        name = 'test_slb'
    #购买slb
        self.enter_my_resource_page()
        self.wait_elevisble(UserMyResourceLocator.reset_button, doc)
        self.click_element(UserMyResourceLocator.reset_button, doc)
        time.sleep(5)
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.get_prod_name_to_click('Server Load Balancer')
        time.sleep(2)
        self.switch_to_new_window()
        time.sleep(5)
        self.wait_elevisble(UserSLBLocator.instance_name, doc)
        self.send_keys(UserSLBLocator.instance_name, name, doc)
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.intranet_button, doc)
        self.click_element(UserSLBLocator.intranet_button, doc)
        time.sleep(2)
        #self.wait_elevisble(UserSLBLocator.vpc_refresh, doc)
        #self.click_element(UserSLBLocator.vpc_refresh, doc)
        #time.sleep(3)
        #self.click_element(UserSLBLocator.vpc_select, doc)
        #time.sleep(2)
        #self.click_element(UserSLBLocator.vpc_first_select, doc)
        #time.sleep(2)
        self.wait_elevisble(UserSLBLocator.vpc_select, doc)
        self.click_element(UserSLBLocator.vpc_select, doc)
        self.wait_elevisble(UserSLBLocator.vpc_option, doc)
        vpc_switch_eles = self.get_elements(UserSLBLocator.vpc_option, doc)
        vpc_switch_eles[0].click()
        self.wait_elevisble(UserSLBLocator.vswitch_select, doc)
        self.click_element(UserSLBLocator.vswitch_select, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.vswitch_first_select, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.buy_now_button, doc)
        self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
        self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        time.sleep(4)
        self.click_element(ProductManagementLocator.term_of_service, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        instance_id = BusinessCommonTools().get_instance_id(cmdopt, get_database_source)
    #修改过期时间触发job
        BusinessCommonTools().update_slb_expired_time(cmdopt, get_database_source)
        BusinessCommonTools().update_job_slb_release_next_trigger_time(cmdopt, get_database_source)
        time.sleep(50)
        self.wait_elevisble(UserMyResourceLocator.reset_button, doc)
        self.click_element(UserMyResourceLocator.reset_button, doc)
        time.sleep(5)
        self.wait_elevisble(UserMyResourceLocator.instance_id_input, doc)
        self.send_keys(UserMyResourceLocator.instance_id_input, instance_id, doc)
        time.sleep(2)
        self.wait_elevisble(UserMyResourceLocator.orgnazation_search, doc)
        self.click_element(UserMyResourceLocator.orgnazation_search, doc)
        time.sleep(2)
        js_object = 'document.getElementsByClassName("antd4-table-content")[0].scrollTo(1000,10000)'
        self.excute_js(js_object);
        time.sleep(2)
        self.check_attribute(self.get_element(UserSLBLocator.slb_status, doc).text, 'Invalid')

    #变配SLB(intranet)
    def slb_instranet_modify(self, cmdopt, get_database_source):
        doc = '变配SLB(intranet)'
        name = 'test_slb1'
        success = 'Release Successfully'
        # 购买slb
        self.enter_my_resource_page()
        self.wait_elevisble(UserMyResourceLocator.reset_button, doc)
        self.click_element(UserMyResourceLocator.reset_button, doc)
        time.sleep(5)
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.get_prod_name_to_click('Server Load Balancer')
        time.sleep(2)
        self.switch_to_new_window()
        time.sleep(5)
        self.wait_elevisble(UserSLBLocator.instance_name, doc)
        self.send_keys(UserSLBLocator.instance_name, name, doc)
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.intranet_button, doc)
        self.click_element(UserSLBLocator.intranet_button, doc)
        time.sleep(2)
        #self.wait_elevisble(UserSLBLocator.vpc_refresh, doc)
        #self.click_element(UserSLBLocator.vpc_refresh, doc)
        #time.sleep(3)
        #self.click_element(UserSLBLocator.vpc_select, doc)
        #time.sleep(2)
        #self.click_element(UserSLBLocator.vpc_first_select, doc)
        #time.sleep(2)
        self.wait_elevisble(UserSLBLocator.vpc_select, doc)
        self.click_element(UserSLBLocator.vpc_select, doc)
        self.wait_elevisble(UserSLBLocator.vpc_option, doc)
        vpc_switch_eles = self.get_elements(UserSLBLocator.vpc_option, doc)
        vpc_switch_eles[0].click()
        self.wait_elevisble(UserSLBLocator.vswitch_select, doc)
        self.click_element(UserSLBLocator.vswitch_select, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.vswitch_first_select, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.buy_now_button, doc)
        self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
        self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        time.sleep(4)
        self.click_element(ProductManagementLocator.term_of_service, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        instance_id = BusinessCommonTools().get_instance_id(cmdopt, get_database_source)
        time.sleep(2)
        self.wait_elevisble(UserMyResourceLocator.instance_id_input, doc)
        self.send_keys(UserMyResourceLocator.instance_id_input, instance_id, doc)
        time.sleep(2)
        self.wait_elevisble(UserMyResourceLocator.reset_button, doc)
        self.click_element(UserMyResourceLocator.reset_button, doc)
        time.sleep(5)
        self.wait_elevisble(UserMyResourceLocator.orgnazation_search, doc)
        self.click_element(UserMyResourceLocator.orgnazation_search, doc)
        time.sleep(5)
        self.wait_elevisble(UserSLBLocator.actions_button, doc)
        self.click_element(UserSLBLocator.actions_button, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.modify_button, doc)
        time.sleep(2)
        self.switch_to_new_window()
        time.sleep(5)
        self.wait_elevisble(UserSLBLocator.instance_type_button, doc)
        self.click_element(UserSLBLocator.instance_type_button, doc)
        time.sleep(2)
        new_instance_type = self.get_element(UserSLBLocator.instance_type, doc).text
        self.click_element(ProductManagementLocator.term_of_service, doc)
        time.sleep(10)
        self.click_element(ProductManagementLocator.buy_now_button, doc)
        self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
        self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        time.sleep(4)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.orders_menu, doc)
        self.click_element(UserSLBLocator.orders_menu, doc)
        time.sleep(2)
        self.orders_clear_status()
        time.sleep(2)
        self.click_element(UserSLBLocator.type_select, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.instance_id_select, doc)
        time.sleep(2)
        self.send_keys(UserSLBLocator.instance_input,instance_id, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.search_button, doc)
        time.sleep(5)
        self.click_element(UserSLBLocator.view_details_button, doc)
        time.sleep(2)
        self.check_attribute(self.get_element(UserSLBLocator.new_instance_type, doc).text, new_instance_type)
        self.enter_my_resource_page()
        time.sleep(5)
        self.wait_elevisble(UserMyResourceLocator.instance_id_input, doc)
        self.send_keys(UserMyResourceLocator.instance_id_input, instance_id, doc)
        time.sleep(2)
        self.wait_elevisble(UserMyResourceLocator.orgnazation_search, doc)
        self.click_element(UserMyResourceLocator.orgnazation_search, doc)
        time.sleep(5)
        self.wait_elevisble(UserSLBLocator.actions_button, doc)
        self.click_element(UserSLBLocator.actions_button, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.release_button, doc)
        time.sleep(2)
        self.switch_to_new_window()
        time.sleep(5)
        self.wait_elevisble(UserSLBLocator.real_release_button, doc)
        self.click_element(UserSLBLocator.real_release_button, doc)
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.confirm_release_button, doc)
        self.click_element(UserSLBLocator.confirm_release_button, doc)
        time.sleep(5)
        self.check_attribute(self.get_element(UserSLBLocator.release_success, doc).text, success)

    def renew_slb(self, cmdopt, instance_id):
        doc = '续费slb'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        self.wait_elevisble(ProductManagementLocator.order_view_detail_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.order_view_detail_button, doc)
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.click_element(ProductManagementLocator.term_of_service, doc)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.pay_button, doc)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])

    # 续费SLB(subscription)
    # def renew_slb_subscription(self, cmdopt, get_database_source):
    #     doc = '续费SLB(subscription)'
    #     name = 'test_slb'
    #     success = 'Release Successfully'
    #     # 购买slb
    #     self.enter_my_resource_page()
    #     self.wait_elevisble(UserMyResourceLocator.reset_button, doc)
    #     self.click_element(UserMyResourceLocator.reset_button, doc)
    #     time.sleep(5)
    #     self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
    #     self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
    #     time.sleep(2)
    #     self.get_prod_name_to_click('Server Load Balancer')
    #     time.sleep(2)
    #     self.switch_to_new_window()
    #     time.sleep(5)
    #     self.wait_elevisble(UserSLBLocator.instance_name, doc)
    #     self.send_keys(UserSLBLocator.instance_name, name, doc)
    #     time.sleep(2)
    #     self.wait_elevisble(UserSLBLocator.intranet_button, doc)
    #     self.click_element(UserSLBLocator.intranet_button, doc)
    #     time.sleep(2)
    #     self.wait_elevisble(UserSLBLocator.vpc_refresh, doc)
    #     self.click_element(UserSLBLocator.vpc_refresh, doc)
    #     time.sleep(3)
    #     self.click_element(UserSLBLocator.vpc_select, doc)
    #     time.sleep(2)
    #     self.click_element(UserSLBLocator.vpc_first_select, doc)
    #     time.sleep(2)
    #     self.wait_elevisble(UserSLBLocator.vswitch_select, doc)
    #     self.click_element(UserSLBLocator.vswitch_select, doc)
    #     time.sleep(2)
    #     self.click_element(UserSLBLocator.vswitch_first_select, doc)
    #     time.sleep(2)
    #     self.click_element(ProductManagementLocator.term_of_service, doc)
    #     time.sleep(10)
    #     self.click_element(ProductManagementLocator.buy_now_button, doc)
    #     self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
    #     self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
    #     time.sleep(4)
    #     self.click_element(ProductManagementLocator.pay_button, doc)
    #     self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
    #     self.driver.close()
    #     all_handles = self.driver.window_handles
    #     self.driver.switch_to.window(all_handles[0])
    #     instance_id = BusinessCommonTools().get_instance_id(cmdopt, get_database_source)
    #     time.sleep(2)
    #     self.wait_elevisble(UserMyResourceLocator.reset_button, doc)
    #     self.click_element(UserMyResourceLocator.reset_button, doc)
    #     time.sleep(5)
    #     self.wait_elevisble(UserMyResourceLocator.instance_id_input, doc)
    #     self.send_keys(UserMyResourceLocator.instance_id_input, instance_id, doc)
    #     time.sleep(2)
    #     self.wait_elevisble(UserMyResourceLocator.orgnazation_search, doc)
    #     self.click_element(UserMyResourceLocator.orgnazation_search, doc)
    #     time.sleep(5)
    #     self.click_element(UserSLBLocator.renew_button, doc)
    #     self.switch_to_new_window()
    #     time.sleep(5)
    #     new_expired_time = self.get_element(UserSLBLocator.new_expiration_date, doc).text
    #     self.click_element(ProductManagementLocator.term_of_service, doc)
    #     time.sleep(10)
    #     self.click_element(ProductManagementLocator.buy_now_button, doc)
    #     self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
    #     self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
    #     time.sleep(4)
    #     self.click_element(ProductManagementLocator.pay_button, doc)
    #     self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
    #     self.driver.close()
    #     all_handles = self.driver.window_handles
    #     self.driver.switch_to.window(all_handles[0])
    #     time.sleep(2)
    #     self.wait_elevisble(UserMyResourceLocator.orgnazation_search, doc)
    #     self.click_element(UserMyResourceLocator.orgnazation_search, doc)
    #     time.sleep(5)
    #     self.check_attribute(self.get_element(UserSLBLocator.new_expired_time, doc).text, new_expired_time)
    #     self.wait_elevisble(UserSLBLocator.actions_button, doc)
    #     self.click_element(UserSLBLocator.actions_button, doc)
    #     time.sleep(2)
    #     self.click_element(UserSLBLocator.release_button, doc)
    #     time.sleep(2)
    #     self.switch_to_new_window()
    #     time.sleep(5)
    #     self.wait_elevisble(UserSLBLocator.real_release_button, doc)
    #     self.click_element(UserSLBLocator.real_release_button, doc)
    #     time.sleep(2)
    #     self.wait_elevisble(UserSLBLocator.confirm_release_button, doc)
    #     self.click_element(UserSLBLocator.confirm_release_button, doc)
    #     time.sleep(5)
    #     self.check_attribute(self.get_element(UserSLBLocator.release_success, doc).text, success)


    #企业用户变更组织
    def change_organization(self, cmdopt, instance_id,org_name):
        doc = '企业用户实例更改组织'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Change Organization')
        self.wait_elevisble(ProductManagementLocator.change_org_to_input, doc)
        time.sleep(2)
        self.send_keys(ProductManagementLocator.change_org_to_input, org_name, doc)
        self.wait_elevisble(ProductManagementLocator().choose_org_name(org_name), doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator().choose_org_name(org_name), doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.change_org_submit_button, doc)
        self.wait_elevisble(ProductManagementLocator.success_prompt, doc)


    # 计费互转(sub-->psgy)
    def sub_to_psgy(self, cmdopt, instance_id):
        doc = '计费互转(sub-->psgy)'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.billing_method_change, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.billing_method_change, doc)
        time.sleep(2)
        self.switch_to_new_window()
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.button_is_enabled(ProductManagementLocator.billing_method_change_buy_now)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.click_element(ProductManagementLocator.term_of_service, doc)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.pay_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])


    def release_slb(self, cmdopt, instance_id):
        doc = '释放slb'
        self.driver.get(Commondata.home_page[cmdopt]['user'])
        self.enter_my_resource_page()
        self.query_intance_id(instance_id)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.action_button, doc)
        time.sleep(2)
        self.get_action_to_click('Release')
        self.switch_to_new_window()
        self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
        self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.release_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.release_button, doc)
        self.wait_elevisble(ProductManagementLocator.buy_now_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.buy_now_button, doc)
        self.wait_elevisble(ProductManagementLocator.release_successful, doc)


# 计费互转(sub-->psgy)
    def psgy_to_sub(self, cmdopt, get_database_source):
        doc = '计费互转(psyg-->sub)'
        name = 'test_slb'
        success = 'Release Successfully'
        self.enter_my_resource_page()
        self.wait_elevisble(UserMyResourceLocator.reset_button, doc)
        self.click_element(UserMyResourceLocator.reset_button, doc)
        time.sleep(5)
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.get_prod_name_to_click('Server Load Balancer')
        time.sleep(2)
        self.switch_to_new_window()
        time.sleep(5)
        self.wait_elevisble(UserSLBLocator.pag_buttoon, doc)
        self.click_element(UserSLBLocator.pag_buttoon, doc)
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.instance_name, doc)
        self.send_keys(UserSLBLocator.instance_name, name, doc)
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.intranet_button, doc)
        self.click_element(UserSLBLocator.intranet_button, doc)
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.vpc_refresh, doc)
        self.click_element(UserSLBLocator.vpc_refresh, doc)
        time.sleep(3)
        self.click_element(UserSLBLocator.vpc_select, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.vpc_first_select, doc)
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.vswitch_select, doc)
        self.click_element(UserSLBLocator.vswitch_select, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.vswitch_first_select, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.buy_now_button, doc)
        self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
        self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        time.sleep(4)
        self.click_element(ProductManagementLocator.term_of_service, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        instance_id = BusinessCommonTools().get_instance_id(cmdopt, get_database_source)
        time.sleep(2)
        self.wait_elevisble(UserMyResourceLocator.reset_button, doc)
        self.click_element(UserMyResourceLocator.reset_button, doc)
        time.sleep(5)
        self.wait_elevisble(UserMyResourceLocator.instance_id_input, doc)
        self.send_keys(UserMyResourceLocator.instance_id_input, instance_id, doc)
        time.sleep(2)
        self.wait_elevisble(UserMyResourceLocator.orgnazation_search, doc)
        self.click_element(UserMyResourceLocator.orgnazation_search, doc)
        time.sleep(5)
        self.click_element(UserSLBLocator.change_billing_method_button, doc)
        time.sleep(2)
        self.switch_to_new_window()
        time.sleep(5)
        self.click_element(UserSLBLocator.buy_now_button, doc)
        self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
        self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        self.click_element(ProductManagementLocator.term_of_service, doc)
        time.sleep(4)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.check_order_button, doc)
        time.sleep(5)
        self.orders_clear_status()
        time.sleep(2)
        self.click_element(UserSLBLocator.type_select, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.instance_id_select, doc)
        time.sleep(2)
        self.send_keys(UserSLBLocator.instance_input, instance_id, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.search_button, doc)
        time.sleep(5)
        self.check_attribute(self.get_element(UserSLBLocator.orders_type, doc).text, 'Change Billing Method')
        self.check_attribute(self.get_element(UserSLBLocator.orders_billing_method, doc).text, 'Subscription')
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        time.sleep(2)
        self.wait_elevisble(UserMyResourceLocator.orgnazation_search, doc)
        self.click_element(UserMyResourceLocator.orgnazation_search, doc)
        time.sleep(5)
        self.wait_elevisble(UserSLBLocator.actions_button, doc)
        self.click_element(UserSLBLocator.actions_button, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.release_button, doc)
        time.sleep(2)
        self.switch_to_new_window()
        time.sleep(5)
        self.wait_elevisble(UserSLBLocator.real_release_button, doc)
        self.click_element(UserSLBLocator.real_release_button, doc)
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.confirm_release_button, doc)
        self.click_element(UserSLBLocator.confirm_release_button, doc)
        time.sleep(5)
        self.check_attribute(self.get_element(UserSLBLocator.release_success, doc).text, success)


    # #进入SLB产品控制台
    # def enter_slb_ascm(self, cmdopt, get_database_source):
    #     doc = '进入SLB产品控制台'
    #     name = 'test_slb'
    #     self.enter_my_resource_page()
    #     self.wait_elevisble(UserMyResourceLocator.reset_button, doc)
    #     self.click_element(UserMyResourceLocator.reset_button, doc)
    #     time.sleep(5)
    #     self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
    #     self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
    #     time.sleep(2)
    #     self.get_prod_name_to_click('Server Load Balancer')
    #     time.sleep(2)
    #     self.switch_to_new_window()
    #     time.sleep(5)
    #     self.wait_elevisble(UserSLBLocator.pag_buttoon, doc)
    #     self.click_element(UserSLBLocator.pag_buttoon, doc)
    #     time.sleep(2)
    #     self.wait_elevisble(UserSLBLocator.instance_name, doc)
    #     self.send_keys(UserSLBLocator.instance_name, name, doc)
    #     time.sleep(2)
    #     self.wait_elevisble(UserSLBLocator.intranet_button, doc)
    #     self.click_element(UserSLBLocator.intranet_button, doc)
    #     time.sleep(2)
    #     self.wait_elevisble(UserSLBLocator.vpc_refresh, doc)
    #     self.click_element(UserSLBLocator.vpc_refresh, doc)
    #     time.sleep(3)
    #     self.click_element(UserSLBLocator.vpc_select, doc)
    #     time.sleep(2)
    #     self.click_element(UserSLBLocator.vpc_first_select, doc)
    #     time.sleep(2)
    #     self.wait_elevisble(UserSLBLocator.vswitch_select, doc)
    #     self.click_element(UserSLBLocator.vswitch_select, doc)
    #     time.sleep(2)
    #     self.click_element(UserSLBLocator.vswitch_first_select, doc)
    #     time.sleep(2)
    #     self.click_element(ProductManagementLocator.term_of_service, doc)
    #     time.sleep(10)
    #     self.click_element(ProductManagementLocator.buy_now_button, doc)
    #     self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
    #     self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
    #     time.sleep(2)
    #     self.click_element(ProductManagementLocator.pay_button, doc)
    #     self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
    #     self.driver.close()
    #     all_handles = self.driver.window_handles
    #     self.driver.switch_to.window(all_handles[0])
    #     instance_id = BusinessCommonTools().get_instance_id(cmdopt, get_database_source)
    #     time.sleep(2)
    #     self.wait_elevisble(UserMyResourceLocator.reset_button, doc)
    #     self.click_element(UserMyResourceLocator.reset_button, doc)
    #     time.sleep(5)
    #     self.wait_elevisble(UserMyResourceLocator.instance_id_input, doc)
    #     self.send_keys(UserMyResourceLocator.instance_id_input, instance_id, doc)
    #     time.sleep(2)
    #     self.wait_elevisble(UserMyResourceLocator.orgnazation_search, doc)
    #     self.click_element(UserMyResourceLocator.orgnazation_search, doc)
    #     time.sleep(5)
    #     self.click_element(UserSLBLocator.instance_id, doc)
    #     time.sleep(100)
    #     self.check_attribute(self.get_element(UserSLBLocator.overview, doc).text, 'Server Load Balancer')


    # #def release(self):
    #     doc = '释放'
    #     success = 'Release Successfully'
    #     self.enter_my_resource_page()
    #     time.sleep(5)
    #     self.click_element(UserMyResourceLocator.reset_button, doc)
    #     time.sleep(2)
    #     self.wait_elevisble(UserSLBLocator.actions_button, doc)
    #     self.click_element(UserSLBLocator.actions_button, doc)
    #     time.sleep(2)
    #     self.click_element(UserSLBLocator.release_button, doc)
    #     time.sleep(2)
    #     self.switch_to_new_window()
    #     time.sleep(5)
    #     self.wait_elevisble(UserSLBLocator.real_release_button, doc)
    #     self.click_element(UserSLBLocator.real_release_button, doc)
    #     time.sleep(2)
    #     self.wait_elevisble(UserSLBLocator.confirm_release_button, doc)
    #     self.click_element(UserSLBLocator.confirm_release_button, doc)
    #     time.sleep(5)
    #     self.check_attribute(self.get_element(UserSLBLocator.release_success, doc).text, success)


    #新增判断按钮是否可以点击方法
    def button_is_enabled(self,locate):
        doc='判断按钮是否可以点击'
        button=self.get_element(locate,doc)
        for i in range(5):
            time.sleep(2)
            if  button.is_enabled():
                button.click()
                break

    # 新增查询产品名称然后点击
    def get_console_product_to_click(self,prouduct_name):
        doc = '查询产品名称然后点击'
        self.wait_elevisble(ProductManagementLocator.product_name_input,doc)
        self.send_keys(ProductManagementLocator.product_name_input,prouduct_name,doc)
        self.wait_elevisble(ProductManagementLocator.search_prod_ele,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.search_prod_ele,doc)
        time.sleep(2)

    #根据instance_name查询对应的id
    def query_instance(self,intance_name):
        doc='查询intance_name'
        self.wait_elevisble(UserSLBLocator.console_instance_name_input,doc)
        self.keyboard_event(UserSLBLocator.console_instance_name_input,doc)
        self.send_keys(UserSLBLocator.console_instance_name_input,intance_name,doc)
        time.sleep(2)
        self.keyboard_event_enter(UserSLBLocator.console_instance_name_input,doc)
        self.wait_elevisble(UserSLBLocator.slb_instance_id_ele,doc)

    # 根据instance_id查询
    def query_intance_id(self,instance_id):
        doc='查询intance_id'
        self.wait_elevisble(ProductManagementLocator.instance_id_input,doc)
        #self.keyboard_event(ProductManagementLocator.instance_id_input,instance_id)
        self.click_element(ProductManagementLocator.instance_id_input, doc)
        self.keyboard_event_all_select(ProductManagementLocator.instance_id_input, doc)
        self.keyboard_event_enter(ProductManagementLocator.instance_id_input, doc)
        time.sleep(2)
        self.send_keys(ProductManagementLocator.instance_id_input,instance_id,doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.product_search,doc)
        time.sleep(5)
        self.wait_elevisble(ProductManagementLocator.order_view_detail_button,doc)


    def get_action_to_click(self,action_name):
        doc='获取操作名称然后点击'
        self.wait_elevisble(ProductManagementLocator.my_resource_action_list,doc)
        action_list_eles =self.get_elements(ProductManagementLocator.my_resource_action_list,doc)
        for action in action_list_eles:
            if action.text== action_name:
                action.click()


    def enter_slb_console(self):
        doc = '进入slb控制台'
        name = 'lsb_'+ CommonTool.generate_string()
        print(name)
        #success = 'Release Successfully'
        self.enter_my_resource_page()
        self.wait_elevisble(ProductManagementLocator.cerate_new_tab, doc)
        self.move_mouse_to_element(ProductManagementLocator.cerate_new_tab)
        time.sleep(2)
        self.get_prod_name_to_click('Server Load Balancer')
        time.sleep(2)
        self.switch_to_new_window()
        time.sleep(5)
        self.wait_elevisble(UserSLBLocator.instance_name, doc)
        self.send_keys(UserSLBLocator.instance_name, name, doc)
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.intranet_button, doc)
        self.click_element(UserSLBLocator.intranet_button, doc)
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.vpc_select, doc)
        self.click_element(UserSLBLocator.vpc_select, doc)
        self.wait_elevisble(UserSLBLocator.vpc_option, doc)
        vpc_switch_eles = self.get_elements(UserSLBLocator.vpc_option, doc)
        vpc_switch_eles[0].click()
        time.sleep(2)
        self.wait_elevisble(UserSLBLocator.vswitch_select, doc)
        self.click_element(UserSLBLocator.vswitch_select, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.vswitch_first_select, doc)
        time.sleep(2)
        self.button_is_enabled(ProductManagementLocator.buy_now_button)
        try:
            self.wait_elevisble(ProductManagementLocator.loading_wait, doc)
            self.wait_eleinvisble(ProductManagementLocator.loading_wait, doc)
        except:
            pass
        self.click_element(ProductManagementLocator.term_of_service, doc)
        time.sleep(2)
        self.wait_elevisble(ProductManagementLocator.pay_button, doc)
        time.sleep(2)
        self.click_element(ProductManagementLocator.pay_button, doc)
        self.wait_elevisble(ProductManagementLocator.pay_successful, doc)
        self.driver.close()
        all_handles = self.driver.window_handles
        self.driver.switch_to.window(all_handles[0])
        time.sleep(2)
        self.click_element(ProductManagementLocator.reset_button, doc)
        time.sleep(2)
        self.click_element(UserSLBLocator.slb_instance_id, doc)
